package com.teradata.multithread.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author: lyndon
 * @version: 1.0
 * @date: 2019/2/24
 */
public class FixThreadPoolDemo implements Runnable {

    private int num;

    static ExecutorService executorService = Executors.newFixedThreadPool(3);

    public FixThreadPoolDemo(int num) {
        this.num = num;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "---" + this.num);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 20; i++) {
            executorService.execute(new FixThreadPoolDemo(i));
        }
        executorService.shutdown();
    }
}
